package net.skyedu.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.SysOutline;
import net.skyedu.dao.DaoSupport;

public class OutNeed extends HttpServlet{
	
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String terid=request.getParameter("periodId");
		String graid=request.getParameter("gradeId");
		String subid=request.getParameter("subjectId");
		String arrangement=request.getParameter("gradationId");
		String callback=request.getParameter("callback");
		List<SysOutline> list=new ArrayList<SysOutline>();
		DaoSupport ds = new DaoSupport();
		 PrintWriter out = response.getWriter();
		if(terid!=null)
		{
			int tempterid=Integer.parseInt(terid);
			
			int tempgraid=Integer.parseInt(graid);
			int tempsubid=Integer.parseInt(subid);
			int arrangeid=Integer.parseInt(arrangement);
			if(tempterid==35)
			{
				list= ds.showOutline(tempterid,tempgraid,arrangeid,tempsubid);
//				out.print(callback+"([ {name:\"跨域访问成功！\"},{id:\"跨域访问失败！\"}])");
				 StringBuffer jsonAttr = new StringBuffer("[");
				 for(int i=0;i<list.size();i++)
				 {
					 SysOutline sys= list.get(i);
					 jsonAttr.append("{");
					 jsonAttr.append("\"TeaAims\":\""+sys.getTeaAims()+"\",");
					 jsonAttr.append("\"Knowledge\":\""+sys.getKnowledge()+"\",");
					 jsonAttr.append("\"ClaContent\":\""+sys.getClaContent()+"\",");
					 jsonAttr.append("\"Difficulty\":\""+sys.getDifficulty()+"\"");
					 jsonAttr.append("}");
					 if(i<list.size()-1){
			    		  jsonAttr.append(",");
			    	  }
				 }
				 jsonAttr.append("]");
				 out.print(callback+"("+jsonAttr.toString()+")");
				 
				 System.out.println(jsonAttr);
			}
			else
			{
				out.print("false");
			}
			
			
			
		}
		else
		{
			out.print("false");
		}
		out.flush();
		out.close();
		
		
		
	}

}
